import { resolutionValue } from '@/api/global/interface'
import { IPersonalTemplate } from '@/api/template/interface'
import { ITemplateTableData } from './interface'
import { t } from 'i18next'

function getEncryptedType(type: number) {
	switch (type) {
		case 0:
			return t('不加密')
		case 2:
			return t('AES加密')
		case 3:
			return t('国密加密')
		case 4:
			return t('国密加密')
		default:
			return t('不加密')
	}
}

export interface IMedia {
	rate: number
	frame: number
	resolution: resolutionValue
}

function getRateText(media: IMedia) {
	if (media.frame === 25 && media.rate === 192 && media.resolution === 14) {
		return t('流畅(192K WCIF@25fps)')
	} else if (media.frame === 25 && media.rate === 256 && media.resolution === 15) {
		return t('标清(256K W4CIF@25fps)')
	} else if (media.frame === 30 && media.rate === 2048 && media.resolution === 12) {
		return t('高清(2M 720p@30fps)')
	} else if (media.frame === 30 && media.rate === 2048 && media.resolution === 13) {
		return t('全高清(2M 1080p@30fps)')
	} else if (media.frame === 60 && media.rate === 4096 && media.resolution === 13) {
		return t('全高清(4M 1080p@60fps)')
	} else if (media.frame === 30 && media.rate === 4096 && media.resolution === 16) {
		return t('超高清(4M 4K@30fps)')
	} else if (media.frame === 60 && media.rate === 8192 && media.resolution === 16) {
		return t('超高清(8M 4K@60fps)')
	} else {
		return t('自定义') + `（${media.rate}Kbps）`
	}
}

function getSfuRateText(param: IMedia) {
	if (param.resolution === 13) {
		return t('全高清(4M 1080p@30fps)')
	} else {
		return t('高清(2M 720p@30fps)')
	}
}

export function transPersonalTemplate(data: IPersonalTemplate[]): ITemplateTableData[] {
	return data.map((item) => {
		let mediaVO = {
			rate: item.bitrate,
			frame: item.frame,
			resolution: item.resolution,
		}
		return {
			templateMoid: item.template_id,
			templateName: item.name,
			templateScale: item.enable_audience === 1 ? t('超大方') : item.max_join_mt + t('方'),
			type: item.conf_type === 2 ? t('超元RTC会议') : item.conf_type === 1 ? t('端口会议') : t('传统会议'),
			e164: item.e164 ? item.e164 : t('无'),
			security: item.safe_conf === 1 ? t('打开', { context: 'SC1' }) : t('关闭', { context: 'SC2' }),
			rate: item.conf_type == 2 ? getSfuRateText(mediaVO) : getRateText(mediaVO),
			mtNum: item.mt_num,
			publicMeeting: item.public_conf ? t('是') : t('否'),
			duration: item.duration,
			permanentMeeting: item.permanent_meeting,
			encryptedType: getEncryptedType(item.encrypted_type),
		}
	})
}
